﻿using System;

namespace NExplorer.Commands
{
	public class NavigateBackCommand : CommandBase
	{
		public NavigateBackCommand()
			: base("Navigate Back")
		{
			ServiceManager.Explorer.CurrentDirectoryChanged += SetEnabled;
            SetEnabled(null, null);
		}

		private void SetEnabled(object sender, EventArgs e)
		{
			Enabled = ServiceManager.Explorer.CanNavigateBack;
		}

		public override void Execute()
		{
			ServiceManager.Explorer.NavigateBack();
		}

        public override void Dispose()
        {
            base.Dispose();

            ServiceManager.Explorer.CurrentDirectoryChanged -= SetEnabled;
        }
	}
}
